from selenium.webdriver.common.by import By
import time
import Login


def bankCard1(name,password,bankName,bankNumber):
    driver = Login.login1(name, password)

    driver.find_element(By.XPATH,'//nav[@class="sidebar-main"]/ul/li[4]').click()
    time.sleep(1)
    driver.find_element(By.XPATH,'//nav[@class="sidebar-main"]/ul/li[4]/ul/li[3]/a').click()
    # 点击银行卡管理
    time.sleep(2)
    driver.find_element(By.XPATH,'//button[@id="bankCard_add_modal_btn"]').click()
    # 新增按钮
    time.sleep(1)
    driver.find_element(By.XPATH,'//input[@id="cardBank_add_input"]').send_keys(bankName)
    driver.find_element(By.XPATH,'//input[@id="cardNum_add_input"]').send_keys(bankNumber)
    driver.find_element(By.XPATH,'//button[@id="bankCard_save_btn"]').click()
    time.sleep(3)

    return driver


def bankCard2(name,password,bankName,bankNumber):
    driver = Login.login1(name, password)

    driver.find_element(By.XPATH,'//nav[@class="sidebar-main"]/ul/li[4]').click()
    time.sleep(1)
    driver.find_element(By.XPATH,'//nav[@class="sidebar-main"]/ul/li[4]/ul/li[3]/a').click()
    # 点击银行卡管理
    time.sleep(2)
    driver.find_element(By.XPATH,'//button[@id="bankCard_add_modal_btn"]').click()
    # 新增按钮
    time.sleep(1)
    driver.find_element(By.XPATH,'//input[@id="cardBank_add_input"]').send_keys(bankName)

    driver.find_element(By.XPATH,"//div[@id='bankCardAddModal']//div[@class='modal-body']/form/div[2]/div[1]/div/label[2]/span").click()
    # 选择信用卡
    time.sleep(1)
    driver.find_element(By.XPATH,'//input[@id="cardNum_add_input"]').send_keys(bankNumber)
    driver.find_element(By.XPATH,'//button[@id="bankCard_save_btn"]').click()
    time.sleep(3)

    return driver


def bankCard3(name,password,args):

    driver = Login.login1(name, password)
    driver.find_element(By.XPATH, '//nav[@class="sidebar-main"]/ul/li[4]').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//nav[@class="sidebar-main"]/ul/li[4]/ul/li[3]/a').click()
    # 点击银行卡管理
    time.sleep(2)
    cards = getBankNum(driver)
    # 银行卡的数量
    cardNums = len(cards)
    cards[0].find_element(By.XPATH,'./div[@class="card"]//ul[@class="card-actions"]/li/button[contains(@class,"delete_btn")]').click()
    # 对第一张银行卡执行删除操作
    time.sleep(2)
    driver.find_element(By.XPATH, f"//div[@class='jconfirm-buttons']/button[{args}]").click()
    # 点击确认按钮
    time.sleep(3)
    # args1 = 1 确认
    # //div[@class='jconfirm-buttons']/button[2]

    return [driver,cardNums]


# 得到银行卡的数量
def getBankNum(driver):
    return driver.find_elements(By.XPATH,"//div[@class='row']/div[not(@class)]/div")


def getBankCard(driver):
    driver.find_element(By.XPATH, '//nav[@class="sidebar-main"]/ul/li[4]').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//nav[@class="sidebar-main"]/ul/li[4]/ul/li[3]/a').click()
    # 点击银行卡管理
    time.sleep(2)


def bankCard4(name,password,name2):
    driver = Login.login1(name, password)

    getBankCard(driver)
    cards = getBankNum(driver)
    # 银行卡的数量
    cards[0].find_element(By.XPATH,'./div[@class="card"]//ul[@class="card-actions"]/li/button[contains(@class,"update_btn")]').click()
    # 对第一张银行卡执行编辑操作
    time.sleep(2)
    ele = driver.find_element(By.XPATH, '//input[@id="cardBank_update_input"]')
    # 银行名称输入框
    name1 = ele.get_attribute("value")
    # 初始银行名
    ele.clear()
    # 清空银行名
    ele.send_keys(name2)
    driver.find_element(By.XPATH, '//button[@id="bankCard_update_btn"]').click()
    # 点击更新按钮
    time.sleep(3)
    cards = getBankNum(driver)
    name3 = cards[0].find_element(By.XPATH, './div/div[contains(@class,"card-header")]/div/h4').text

    return [driver,name1,name3]


def bankCard5(name,password,card2):
    driver = Login.login1(name, password)

    getBankCard(driver)
    cards = getBankNum(driver)
    # 银行卡的数量
    cards[0].find_element(By.XPATH,'./div[@class="card"]//ul[@class="card-actions"]/li/button[contains(@class,"update_btn")]').click()
    # 对第一张银行卡执行编辑操作
    time.sleep(2)
    ele = driver.find_element(By.XPATH,'//input[@id="cardNum_update_input"]')
    # 银行卡号输入框
    card1 = ele.get_attribute("value")
    # 初始值
    ele.clear()
    # 清空
    ele.send_keys(card2)
    driver.find_element(By.XPATH, '//button[@id="bankCard_update_btn"]').click()
    # 点击更新按钮
    time.sleep(3)
    cards = getBankNum(driver)
    card3 = cards[0].find_element(By.XPATH, './div/div[@class="card-body"]/h4[1]').text

    return [driver,card1,card3]


def bankCard6(name,password):
    driver = Login.login1(name, password)

    getBankCard(driver)
    cards = getBankNum(driver)
    # 银行卡的数量
    cards[0].find_element(By.XPATH,'./div[@class="card"]//ul[@class="card-actions"]/li/button[contains(@class,"update_btn")]').click()
    # 对第一张银行卡执行编辑操作
    time.sleep(2)
    driver.find_element(By.XPATH,'//div[@id="bankCardUpdateModal"]/div//form/div[2]/div[1]/div/label[2]/span').click()
    # 选择信用卡
    driver.find_element(By.XPATH,'//button[@id="bankCard_update_btn"]').click()
    # 点击更新按钮
    time.sleep(2)

    return driver